﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Job.Web.Framework;
using Job.Logic.BaseContent;
namespace Job.Web.userControls.Admin
{
    public partial class HunterJobList : BaseCtrl
    {
        HunterJobLogic logic = new HunterJobLogic();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                BindCount();
                BindData();
            }
        }

        private void BindCount()
        {
            //AspNetPagerInit.InitPager(pagerButtom);
            pagerButtom.RecordCount = logic.GetCount();
            pagerButtom.DataBind();
        }

        void BindData()
        {
            int pageSize = pagerButtom.PageSize;
            int pageIdx = pagerButtom.CurrentPageIndex;
            this.gridJobs.DataSource = logic.GetJobPageList(pageSize,pageIdx);
            this.gridJobs.DataBind();
        }

        protected void pagerButtom_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        protected void gridJobs_RowEditing(object sender, GridViewEditEventArgs e)
        {
            int row = e.NewEditIndex;
            Label label = (Label)gridJobs.Rows[row].FindControl("lbJobId");
            string jobId = label.Text;

            string url = "AdminMain.aspx?controlType=" 
                + Convert.ToString((int)Constants.SubjectType.HunterPositionIfo)
                + "&jobId=" + jobId;

            Response.Redirect(url);
        }

        protected void gridJobs_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int row = e.RowIndex;
            Label label = (Label)gridJobs.Rows[row].FindControl("lbJobId");
            string jobId = label.Text;

            HunterJobLogic logic = new HunterJobLogic();
            logic.DeleteById(Convert.ToInt32(jobId));

            BindCount();
            BindData();
        }

        protected void btNew_Click(object sender, EventArgs e)
        {
            string url = "AdminMain.aspx?controlType="
                + Convert.ToString((int)Constants.SubjectType.HunterPositionIfo);

            Response.Redirect(url);
        }

        protected void gridJobs_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if ( e.Row.RowType == DataControlRowType.DataRow ) 
            {
                if (e.Row.RowIndex > -1) 
                {
                    LinkButton lbtnDelete = (LinkButton)e.Row.Cells[7].Controls[0];
                    if ( lbtnDelete != null && lbtnDelete.Text.Equals("删除") ) 
                    {
                        lbtnDelete.Attributes.Add("onClick", "return confirm('是否确认删除？')");
                    }
                }
            }
        }

    }
}